/* GUI CONVERTED from ecapsbmt.p (converter v1.76) Tue Dec 31 10:44:58 2002 */
/* ecapsbmt.p - PCO/PCR SUBMIT                                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.13.1.10 $                                               */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.4    LAST EDIT:   08/06/93   MODIFIED BY: QZL *H013*     */
/*                               10/27/94   MODIFIED BY: ame *H578*     */
/*                               04/11/95   MODIFIED BY: ame *H0CF*     */
/*                               04/24/95                srk *H0D8*     */
/* REVISION: 7.4    LAST EDIT:   11/12/96   BY: *H0P4* Julie Milligan   */
/* REVISION: 8.6    LAST EDIT:   12/02/96   BY: Joe Gawel *K00C*/
/* REVISION: 8.6    LAST EDIT:   02/25/97   BY: Joe Gawel *K05X*/
/* REVISION: 8.6    LAST EDIT:   04/04/97   BY: *H0VN* Russ Witt        */
/* REVISION: 8.6    LAST EDIT:   05/22/97   BY: Joe Gawel *K0CG*        */
/* REVISION: 8.6    LAST EDIT:   07/18/97   BY: Amy Esau  *K0GM*        */
/* REVISION: 8.6    LAST EDIT:   10/07/97   BY: John Worden *K0LP*      */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E     LAST MODIFIED: 07/24/98   BY: *K1VR* Niranjan R.    */
/* REVISION: 8.6E     LAST MODIFIED: 09/15/98   BY: *K1X1* John Worden    */
/* REVISION: 8.6E     LAST MODIFIED: 01/14/99   BY: *K1YX* Mugdha Tambe   */
/* REVISION: 9.0      LAST MODIFIED: 08/20/99   BY: *J3DF* Mugdha Tambe   */
/* REVISION: 9.0      LAST MODIFIED: 12/06/99   BY: *K24J* Jyoti Thatte   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 07/11/00 BY: *N0FJ* Mudit Mehta      */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *H0HM*                    */
/* Revision: 1.13.1.8     BY: Katie Hilbert         DATE: 05/15/02  ECO: *P06H*  */
/* Revision: 1.13.1.9     BY: Annasaheb Rahane      DATE: 07/17/02  ECO: *N1PC*  */
/* $Revision: 1.13.1.10 $   BY: Katie Hilbert         DATE: 12/27/02  ECO: *P0L8*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */
define input parameter ecr_ecn like ecm_doc_type.
define new shared variable cmtindx    as integer.
define new shared variable type       like ecl_type.
define new shared variable local_type like ecm_type.

define variable ecmnbr     like ecm_nbr.
define variable ecmid      like wo_lot.
define variable dbase      like si_db.
define variable ecmnbr2    like ecm_nbr.
define variable ecmid2     like wo_lot.
define variable dbase2     like si_db.
define variable ecmassign  like ecm_assign.
define variable ecmtype    like ecm_type.
define variable ecmassign2 like ecm_assign no-undo.
define variable ecmtype2   like ecm_type no-undo.
define variable ecminit    like ecm_init.
define variable unsubmit   like mfc_logical.
define variable subm       like mfc_logical.
define variable cmmt       like mfc_logical initial no.
define variable yn         like mfc_logical.
define variable leave-c    like mfc_logical no-undo.
define variable p-doctype  like rsu_doc_type.
define variable p-docnbr   like rsu_doc_nbr.
define variable p-slip     like rst_appr_code.
define variable p-index    like rsu_index.
define variable p-docloc   like rsu_user1.

define new shared frame d.

define workfile sub_que
   field    ecm__nbr     like ecm_nbr
   field    ecm__id      like wo_lot
   field    ecm__dbase   like si_db
   field    ecm__cmtindx like ecm_cmtindx
   field    ecm__title   like ecm_title format "x(26)"
   field    ecm__type    like ecm_type
   field    ecm__assign  like ecm_assign
   field    ecm__init    like ecm_init
   field    ecm__subdate like ecm_sub_date
   field    ecm__reprocess like ecm_reprocess.

{ecwndvar.i}  /*scrolling window variables*/


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
ecmnbr               colon 9  label "Number"
   ecmid                colon 30
   dbase                colon 48 label "DBase"
   ecr_ecn              colon 72 format "x(3)" label "DocType"
   ecmtype              colon 9
   ecmassign            colon 30 label "Dsgn Grp"
   ecminit              colon 48 label "By"
   unsubmit             colon 72 label "Unsubmt Only"
 SKIP(.4)  /*GUI*/
with frame a width 80 side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   ecmnbr2              column-label "Number"
   ecmid2
   dbase2
   ecm__title
   ecm__init
   subm                 column-label "Sbmt"
   cmmt                 column-label "Cmmt"
with frame c width 80 with 1 down attr-space THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

FORM /*GUI*/ 
   ecmtype2                column-label "PCC Type"
   ecmassign2              column-label "Dsgn Group"
   pct_doc_type            no-label
with frame d width 29 title
   color normal (getFrameTitle("DOCUMENT_FOR_RE-PROCESS",33))
   row 5 centered overlay attr-space THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

FORM /*GUI*/  with overlay frame w1 THREE-D /*GUI*/.


/*V8:HiddenDownFrame=w1 */

assign
   unsubmit    = yes
   type        = "30"
   window_row  = 6
   window_down = 5.

find first pcc_ctrl no-lock no-error.
if (available pcc_ctrl and pcc_initial_date = ?)
   or not available pcc_ctrl then do:
   /*ECO Maintenance not disabled*/
   {pxmsg.i &MSGNUM=5652 &ERRORLEVEL=4}
   hide message.
   return.
end.

loop-a:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

   hide frame a no-pause.
   hide frame w1 no-pause.
   hide frame c no-pause.
   view frame a.
   view frame w1.
   view frame c.

   global_recid = ?.
   update
      ecmnbr
      ecmid
      dbase
      ecr_ecn
      ecmtype
      ecmassign
      ecminit
      unsubmit
   with frame a
   editing:
      if frame-field = "ecmnbr" then do:

         {mfnp05.i ecm_mstr ecm_mstr
            "((ecm_rel_date = ?) and (not ecm_batched) and
              (ecm_appr_date = ?) and (ecm_close_date = ?))"
            ecm_nbr "input ecmnbr"}
         if global_recid <> ? then do:
            recno = global_recid.
            find ecm_mstr where recid(ecm_mstr) = recno
               no-error.
            global_recid = ?.
         end.

         if recno <> ? then
            display
               substring(ecm_nbr,1,8)  @ ecmnbr
               substring(ecm_nbr,9,8)  @ ecmid
               substring(ecm_nbr,17,8) @ dbase
               ecm_type    @ ecmtype
               ecm_assign  @ ecmassign
               ecm_init    @ ecminit
            with frame a.
      end.
      else if frame-field = "ecmtype" then do:
         global_recid = ?.

         {mfnp.i pct_mstr ecmtype  pct_type ecmtype pct_type pct_type}
         if global_recid <> ? then do:
            recno = global_recid.

            find pct_mstr where recid(pct_mstr) = recno no-error.
            global_recid = ?.
         end.

         if recno <> ? then
            display
               pct_type     @ ecmtype
               pct_dsgn_grp @ ecmassign
            with frame a.
      end.
      else if frame-field = "ecminit" then do:
         recno = ?.
         {mfnp.i usr_mstr ecminit usr_userid ecminit usr_userid
            usr_userid }
         if recno <> ? then display usr_userid @ ecminit with frame a.
      end.
      else do:
         readkey.
         apply lastkey.
      end.
   end.
   global_recid = ?.

   for each sub_que exclusive-lock:
      delete sub_que.
   end.

   assign
      ecmnbr = string(ecmnbr, "x(8)")
      ecmid  = string(ecmid, "x(8)")
      dbase  = string(dbase, "x(8)").

   for each ecm_mstr where
      (substring(ecm_nbr,1,8) >= ecmnbr or ecmnbr = "")   and
      (substring(ecm_nbr,9,8)  = ecmid  or ecmid  = "")   and
      (substring(ecm_nbr,17,8) = dbase  or dbase  = "")   and
      (trim(string(substring(ecm_nbr,25,1),"x(1)")) = "") and
      (ecm_type = ecmtype or ecmtype = "")                and
      (ecm_assign = ecmassign or ecmassign = "")          and
      (ecm_init = ecminit or ecminit = "")                and
      ecm_appr_date = ? and ecm_rel_date = ?              and
      not ecm_batched and
      ecm_close_date = ? and (ecm_sub_date = ? or
      (ecm_sub_date <> ? and not unsubmit)) and
      ecm_doc_type = ecr_ecn no-lock:
      create sub_que.
      assign
         ecm__nbr       = substring(ecm_nbr,1,8)
         ecm__id        = substring(ecm_nbr,9,8)
         ecm__dbase     = substring(ecm_nbr,17,8)
         ecm__cmtindx   = ecm_cmtindx
         ecm__title     = ecm_title
         ecm__type      = ecm_type
         ecm__assign    = ecm_assign
         ecm__init      = ecm_init
         ecm__subdate   = ecm_sub_date
         ecm__reprocess = ecm_reprocess.
   end.

   loop-b:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      clear frame c no-pause.
      clear frame w1 all no-pause.

      if keyfunction(lastkey) = "END-ERROR"
         and leave-c = no then undo loop-a, retry.
      {ecwindow.i sub_que
         "ecm__nbr ecm__id ecm__dbase
           ecm__title
           ecm__init ecm__subdate"
         ecm__nbr
         "/**/"
         "yes"
         """"
         "width 80 attr-space"
         "1"
         "ecm__nbr ecm__id ecm__dbase"}
      leave-c = no.
      global_recid = recidarray[i].

      if keyfunction(lastkey) = "GO"
         or lastkey = keycode("RETURN") then
      block-c:
      do transaction with frame c on endkey undo loop-b, retry loop-b:
/*GUI*/ if global-beam-me-up then undo, leave.

         leave-c = yes.
         global_recid = recidarray[i].
         hide frame d no-pause.

         find sub_que where recid(sub_que) = global_recid no-error.
         if available sub_que then do:
            if ecm__cmtindx = 0 then cmmt = no.
            else cmmt = yes.
            subm   = yes.
            if ecm__subdate <> ?
            then
               display subm.
            else
               display "" @ subm.
            display
               ecm__nbr   @ ecmnbr2
               ecm__id    @ ecmid2
               ecm__dbase @ dbase2
               ecm__title
               ecm__init
               cmmt
            with frame c.

            set ecmnbr2 ecmid2 dbase2 with frame c
            editing:
               if frame-field = "ecmnbr2" then do:
                  global_recid = ?.

                  {mfnp05.i ecm_mstr ecm_mstr
                     "(trim(substring(ecm_nbr,25,1)) = """" and
                       (ecm_type = ecmtype or ecmtype = """") and
                       (ecm_assign = ecmassign or ecmassign = """") and
                       (ecm_init = ecminit or ecminit = """") and
                       ecm_appr_date = ? and ecm_rel_date = ? and
                       not ecm_batched and
                       ecm_close_date = ? and (ecm_sub_date = ? or
                       (ecm_sub_date <> ? and not unsubmit)) and
                       ecm_doc_type = string(ecr_ecn))" ecm_nbr "input ecmnbr2"}

                  if global_recid <> ? then do:
                     recno = global_recid.
                     find ecm_mstr where recid(ecm_mstr) = recno no-lock
                        no-error.
                  end.

                  if recno <> ? then do:
                     if ecm_cmtindx = 0 then cmmt = no.
                     else cmmt = yes.
                     if ecm_sub_date <> ? then display subm  .
                     else display "" @ subm  .
                     display
                        substring(ecm_nbr,1,8)  @ ecmnbr2
                        substring(ecm_nbr,9,8)  @ ecmid2
                        substring(ecm_nbr,17,8) @ dbase2
                        ecm_init                @ ecm__init
                        cmmt.
                  end.
               end.
               else do:
                  readkey.
                  apply lastkey.
               end.
            end.

            assign
               ecmnbr2 = string(ecmnbr2, "x(8)")
               ecmid2  = string(ecmid2, "x(8)")
               dbase2  = string(dbase2, "x(8)").

            find first sub_que
               where ecm__nbr   = ecmnbr2 and
                     ecm__id    = ecmid2  and
                     ecm__dbase = dbase2 no-error.
            if not available sub_que then do:
               /* No record available based on selection criteria */
               {pxmsg.i &MSGNUM=5657 &ERRORLEVEL=3}
               hide message.
               undo block-c, leave block-c.
            end.

            find ecm_mstr
               where ecm_nbr = string(ecmnbr2,"x(8)")
                             + string(ecmid2,"x(8)")
                             + string(dbase2,"x(8)")
            exclusive-lock no-error no-wait.
            if locked(ecm_mstr) then do:
               /* Record locked by another user.  Try later */
               {pxmsg.i &MSGNUM=7422 &ERRORLEVEL=4}
               hide message.
               undo block-c, leave block-c.
            end.
            if not available ecm_mstr then do:
               /* DATA CHANGED AND RERUN THIS PROGRAM REQUIRED */
               {pxmsg.i &MSGNUM=5629 &ERRORLEVEL=3}
               undo loop-a, retry loop-a.
            end.

            if ecm_cmtindx = 0 then cmmt = no.
            else cmmt = yes.

            find last rsu_mstr
               where rsu_doc_nbr = string(ecmnbr2,"x(8)")
                                 + string(ecmid2,"x(8)")
                                 + string(dbase2,"x(8)")
               no-lock no-error.

            if ecm_reprocess then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


               {gprun.i ""ecapsmta.p""
                  "( input recid(ecm_mstr),
                    input-output ecmtype2,
                    input-output ecmassign2,
                    input-output yn
                    )"}
/*GUI*/ if global-beam-me-up then undo, leave.


               global_recid = ?.

               if not yn then do:
                  hide frame d no-pause.
                  undo block-c, retry block-c.
               end.

               assign
                  ecm__reprocess = no
                  ecm_assign     = ecmassign2
                  ecm_type       = ecmtype2
                  ecm_reprocess  = no.

               /* THE ROUTING SLIP FOR THE NEW TYPE/GROUP */
               /* IS FOUND AND STORED IN ECM_APPROVAL     */

               for first pct_mstr
                  fields (pct_approval pct_doc_type
                          pct_dsgn_grp pct_type)
                  where pct_type     = ecmtype2
                    and pct_dsgn_grp = ecmassign2 no-lock:
               ecm_approval = pct_approval.
               end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR FIRST PCT_MSTR */

            end.
            hide frame d no-pause.

            do on endkey undo block-c, leave block-c
                  on error undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.

               update subm   cmmt with frame c.
               if subm   then do:
                  assign
                     p-docnbr  = ecm_mstr.ecm_nbr
                     p-doctype = ecm_doc_type
                     p-slip    = ecm_approval.
                  {gprun.i ""pcrteap.p"" "(p-docnbr, p-doctype,
                       p-docloc, p-slip,
                       output p-index)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  /* ASSIGNING CURRENT DATE WHEN SUBMIT */
                  assign
                     ecm_sub_date = today
                     ecm__subdate = today.

               end. /*IF subm   THEN DO */

               assign
                  ecm_mstr.ecm_mod_date = today
                  ecm_mstr.ecm_userid = global_userid.

               /* ASSIGNING BLANK WHEN UN-SUBMIT SELECTED */
               if not subm   then do:

                  if available rsu_mstr and
                     can-find(first rsud_det
                     where rsud_index = rsu_index
                     and   rsud_approved = yes )
                  then do:
                     /* PCO/PCR approval exists.          */
                     /* Submit/Unsubmit needs disapproval */
                     {pxmsg.i &MSGNUM=2159 &ERRORLEVEL=3}
                     hide message.
                     undo block-c, retry block-c.
                  end.

                  assign
                     ecm_sub_date = ?
                     ecm__subdate = ?.

                  for each rsu_mstr
                     where rsu_doc_nbr  = ecm_nbr and
                           rsu_doc_type = ecm_doc_type
                     exclusive-lock:
                     for each rsud_det where rsud_index = rsu_index
                        exclusive-lock:
                        delete rsud_det.
                     end.
                     delete rsu_mstr.
                  end.

               end. /* IF NOT subm   THEN DO */

               if cmmt then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                  hide frame w1 no-pause.
                  hide frame c no-pause.
                  assign
                     global_ref = getTermLabel("COMMENTS",8)    + " - " +
                                  getTermLabel("SUBMISSION",10) + ", " +
                                  getTermLabel("APPROVAL",8)    + ", " +
                                  getTermLabel("RELEASE",7)
                     cmtindx = ecm_cmtindx.

                  {gprun.i ""gpcmmt01.p"" "(input ""ecm_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  assign
                     ecm_cmtindx = cmtindx
                     ecm__cmtindx = cmtindx
                     global_ref = "".
                  view frame a.
                  release ecm_mstr.
               end.
/*GUI*/ if global-beam-me-up then undo, leave.

               view frame w1.
               view frame c.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            release ecm_mstr.
            clear frame c no-pause.
            find first sub_que
               where ecm__nbr = ecmnbr2 and
                     ecm__id  = ecmid2  and
                     ecm__dbase = dbase2
            no-error.
            if available sub_que then global_recid = recid(sub_que).
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* end of loop-b */
end.  /* end of loop-a */
global_recid = ?.
